package com.axjy.service.impl;

import com.axjy.controller.dto.UserDto;
import com.axjy.dao.UserMapper;
import com.axjy.pojo.User;
import com.axjy.service.UserService;
import com.axjy.util.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by asus on 2017/9/25.
 */
@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public Pager searchPager(Integer offset, Integer limit, String columnName, String columnValue) {
       Pager pager=new Pager();
       pager.setRows(userMapper.search(offset,limit,columnName,columnValue));
       pager.setTotal(userMapper.getTotal(columnName,columnValue));
        return pager;
    }

    @Override
    public void grant(Integer id, Integer roleId) {
        userMapper.updateRole(id,roleId);
    }

    @Override
    public User login(String name, String pwd) {
       User user= userMapper.searchUser(name,pwd);
       return user;
    }

    @Override
    public List<User> searchByRole(Integer rid) {
        return userMapper.searchByRole(rid);
    }

    @Override
    public Pager searchByDyna(Integer offset, Integer limit, UserDto dto) {
        Pager pager=new Pager();
        pager.setRows(userMapper.searchByDyna(offset,limit,dto));
        pager.setTotal(userMapper.getTotalByDyna(dto));
        return pager;
    }
}
